//
//  HLHomeDiscountCell.m
//  YueYue
//
//  Created by hulu001 on 2023/8/15.
//

#import "HLHomeDiscountCell.h"

@interface HLHomeDiscountCell ()

@property (nonatomic, strong) UIImageView *iconView;

@property (nonatomic, strong) UILabel *nicknameLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *unitLabel;
@property (nonatomic, strong) QMUILabel *discountLabel;

@end

@implementation HLHomeDiscountCell

-(instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        [self setupView];
    }
    return self;
    
}

- (void)setupView {
    self.iconView = [[UIImageView alloc] init];
    _iconView.userInteractionEnabled = NO;
    _iconView.layer.masksToBounds = YES;
    _iconView.layer.cornerRadius = 25;
    _iconView.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:_iconView];
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(4);
        make.size.mas_equalTo(50);
        make.centerY.mas_equalTo(0);
    }];
    
    
    self.discountLabel = [[QMUILabel alloc] qmui_initWithFont:UIFontMediumMake(8) textColor:UIColorWhite];
    _discountLabel.backgroundColor = [UIColor qmui_colorWithHexString:@"#F48B01"];
    _discountLabel.contentEdgeInsets = UIEdgeInsetsMake(2, 4, 2, 4);
    _discountLabel.layer.masksToBounds = YES;
    _discountLabel.layer.cornerRadius = 8;
    _discountLabel.text = @"折扣";
    [self.contentView addSubview:_discountLabel];
    [_discountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_iconView.mas_top).offset(6);
        make.left.equalTo(_iconView.mas_centerX);
    }];
    
    self.nicknameLabel = [[UILabel alloc] qmui_initWithFont:UIFontMake(12) textColor:UIColorWhite];
    [self.contentView addSubview:_nicknameLabel];
    [_nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconView.mas_right).offset(4);
        make.centerY.mas_equalTo(-10);
    }];
    
    self.priceLabel = [[UILabel alloc] qmui_initWithFont:UIFontMediumMake(12) textColor:[UIColor qmui_colorWithHexString:@"#F48B01"]];
    _priceLabel.text = @"19";
    [self.contentView addSubview:_priceLabel];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_nicknameLabel);
        make.centerY.mas_equalTo(10);
    }];
    
    self.unitLabel = [[UILabel alloc] qmui_initWithFont:UIFontMake(10) textColor:UIColorWhite];
    _unitLabel.text = @"金币/30秒";
    [self.contentView addSubview:_unitLabel];
    [_unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_priceLabel.mas_right);
        make.centerY.equalTo(_priceLabel);
    }];
    
}

- (void)setModel:(HLHomeListModel *)model
{
    _model = model;
    [_iconView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[HLUIHelper avatarBigPlaceholder]];
    _nicknameLabel.text = model.nickName;
    _priceLabel.text = @"99";//[NSString stringWithFormat:@"%ld", [model.videoUnitPrice integerValue]];
    _discountLabel.hidden = ![model.isDiscount boolValue];
    
}

@end
